#include "dpvs.h"

#include "channel.h"
#include "config.h"
#include "error.h"
#include "node.h"
#include "pipe.h"
#include "view.h"
#include "window.h"
#include "body.h"
#include <stdlib.h>

class NodeFactory : public eq::NodeFactory
{
public:
    virtual eq::Config*  createConfig( eq::ServerPtr parent )
        { return new eqPc::Config( parent ); }
    virtual eq::Node*    createNode( eq::Config* parent )  
        { return new eqPc::Node( parent ); }
    virtual eq::Pipe*    createPipe( eq::Node* parent )
        { return new eqPc::Pipe( parent ); }
    virtual eq::Window*  createWindow( eq::Pipe* parent )
        { return new eqPc::Window( parent ); }
    virtual eq::Channel* createChannel( eq::Window* parent )
        { return new eqPc::Channel( parent ); }
    virtual eq::View* createView( eq::Layout* parent )
        { return new eqPc::View( parent ); }
};

int main( const int argc, char** argv )
{



    // 1. Equalizer initialization
    NodeFactory nodeFactory;
    eqPc::initErrors();

    if( !eq::init( argc, argv, &nodeFactory ))
    {
        EQERROR << "Equalizer init failed" << std::endl;
        return EXIT_FAILURE;
    }

    // 2. parse arguments
    eqPc::LocalInitData initData;
    initData.parseArguments( argc, argv );

    // 3. initialization of local client node
    co::base::RefPtr< eqPc::EqPc > client = new eqPc::EqPc( initData );
    if( !client->initLocal( argc, argv ))
    {
        EQERROR << "Can't init client" << std::endl;
        eq::exit();
        return EXIT_FAILURE;
    }

    // 4. run client
    const int ret = client->run();

    // 5. cleanup and exit
    client->exitLocal();

    EQASSERTINFO( client->getRefCount() == 1, client );
    client = 0;

    eq::exit();
    eqPc::exitErrors();
    return ret;
}